package com.itwlj.mapper;

import com.itwlj.annotation.AutoFill;
import com.itwlj.entity.Category;
import com.itwlj.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 新增分类
     *
     * @param category
     */
    @Insert("insert into category(name, sort, create_time, update_time, create_user, update_user) " +
            "values (#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Category category);

    /**
     * 查询分类
     *
     * @return
     */
    @Select("select id, name, sort, update_time from category order by sort")
    List<Category> list();

    /**
     * 根据id删除分类
     *
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id修改分类
     *
     * @param category
     */
    @Update("update category set name = #{name} ,sort = #{sort} ,update_time = #{updateTime},update_user = #{updateUser} where id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void update(Category category);

    /**
     * 根据id查询分类
     *
     * @param id
     * @return
     */
    @Select("select * from category where id = #{id}")
    Category getById(Long id);
}
